package com.kmist.xiakexing.tools;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Config {

    public static Context context;
    private static SimpleDateFormat simpleDateFormat;
    private static Date date;

    public static void Alarm(String w){
        Toast.makeText(context, w,Toast.LENGTH_SHORT).show();
    }
    public static String data(){
        if (simpleDateFormat == null) {
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

    public static final String SERVICEADDRESS = "192.168.1.6";
    public static final int SERVICEADDRPORT = 1125;

    public static final String DATABASE_NAME = "xkx1000.db";
    public static final int DATABASE_VERSION = 1;

    public static final String TABLE_NAME_GAME= "game";
    public static final String TABLE_NAME_MIDENEMY= "midenemy";
    public static final String TABLE_NAME_ENEMYLIB= "enemy";
    public static final String TABLE_NAME_USERINFO= "userinfo";



    public static final String TABLE_NAME_MAP = "map";
    public static final String TABLE_NAME_MAP_EXITS = "map_exits";
    public static final String TABLE_NAME_MAP_ITEM = "map_item";    //地图物品表格
    public static final String TABLE_NAME_MAP_OBJ = "map_object";    //地图物品表格
    public static final String TABLE_NAME_KEDIAN = "kedian";
    public static void Debug(String w, String e){
        Log.d(w,e);
    }
    public static void Debug(String e){
        Log.d("Log",e);
    }

    public static JSONObject val2json(String mibName, int mibValue){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(mibName, mibValue);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    public static JSONObject val2json(String mibName, String mibValue){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(mibName, mibValue);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    /*
     * 将时间转换为时间戳
     */
    public static long dateToStamp(String time) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(time);
        return date.getTime();
    }

    /*
     * 将时间戳转换为时间
     */
    public static String stampToDate(long timeMillis){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(timeMillis);
        return simpleDateFormat.format(date);
    }
}
